home *** CD-ROM | disk | FTP | other *** search
- Path: sooner.net!usenet
- From: Eddie Bush <edwbush@sooner.net>
- Newsgroups: comp.lang.c
- Subject: Recursion
- Date: Wed, 03 Apr 1996 01:58:26 -0800
- Organization: sooner.net news site
- Message-ID: <31624BC2.70D2@sooner.net>
- NNTP-Posting-Host: p22.sooner.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- I am trying to construct a C function that will recursively convert
- a string such as "1234" into it's integer equivelant (1234).
-
- Here is what I know:
- 1)if you subtract the character "0" from any of the other digits "1".."9"
- you will get the integer value of that characer.
- Example: "1" - "0" is equal to 1
- "2" - "0" is equal to 2
- .
- .
- .
- "9" - "0" is equal to 9
- 2)the function should be called with a character pointer:
- Such as: convert("1234");
- making the prototype look something like:
- int convert(char *p);
-
- Does anyone have an idea? This is sorta stumping me. I am aware of
- atoi, but I am wanting to write a recursive function that does that --
- for the fun of it. It's sort of a little puzzle to help me learn
- recursion. Any ideas?
-
- Thanx in Advance!
-